<?php
/**
 * Created by PhpStorm.
 * User: chy
 * Date: 2017/3/30
 * Time: 15:24
 */
use yii\helpers\Url;
use \common\models\Catalog;
$navItems = Catalog::getNavItems(2);
$alias=Yii::$app->view->params['alias'];
?>
<div class="pull-left">
    <p>产品展示<br><span>PRODUCT</span></p>
    <ul>
        <?php
        for($i=0;$i<count($navItems);$i++){
            $nav=$navItems[$i];
            if($nav['name']=='公司简介'){
              continue;
            }
            ?>
            <li data-url="<?=Url::to(['/catalog','alias'=>$nav['alias']])?>" data-alias="<?=$nav['alias']?>" class="<?=$i==0?'on':''?>" onclick="ajaxProduct(this,'<?=$nav['alias']?>');"><a href="javascript:"><?=$nav['name']?><span><img src="images/flag<?=$i+1?>.png"></span></a></li>
        <?php
        }
        ?>
        <li></li>
    </ul>
</div>
<div class="pull-right" id="product-list">
</div>
<script>
    var c_alias='<?=$alias?>';
    //list单页个数,page是否分页
    function ajaxProduct(obj,alias) {
        if(c_alias=='') {
            $(".pull-left ul li").removeClass("on");
            $(obj).addClass("on");
            $.get("<?=Url::toRoute('base/ajax-product')?>",
                {
                    alias: alias,
                    list: list,
                    paging: paging
                },
                function (data, status) {
                    $("#product-list").empty();
                    $("#product-list").append(data);
                });
        }else{
            window.location.href=$(obj).attr("data-url");
        }
    }
    $(function(){
        $(".pull-left ul li").removeClass("on");
       if(c_alias=='') {
           var a=$(".pull-left ul li").eq(0).attr("data-alias");
           $(".pull-left ul li").eq(0).addClass("on");
           $.get("<?=Url::toRoute('base/ajax-product')?>",
               {
                   alias:a,
                   list:list,
                   paging:paging
               },
               function(data,status){
                   $("#product-list").empty();
                   $("#product-list").append(data);
               });
       }else {
           $(".pull-left ul li").each(function () {
               if ($(this).attr("data-alias") == c_alias) {
                   var a=$(this).attr("data-alias");
                   $(this).addClass("on");
                   $.get("<?=Url::toRoute('base/ajax-product')?>",
                       {
                           alias:a,
                           list:list,
                           paging:paging
                       },
                       function(data,status){
                           $("#product-list").empty();
                           $("#product-list").append(data);
                       });
               }
           });
       }
    });
</script>